package com.food.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.food.dao.service.ManagerService;
import com.food.model.Manager;


@WebServlet("/manager/AddManager")
public class AddManager extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=utf-8");
		
		String mgaccount = request.getParameter("mgaccount");
		String mgpasswordStr = request.getParameter("mgpassword");
		String mgname = request.getParameter("mgname");
		String mgidentity = request.getParameter("mgidentity");
		String mgemail = request.getParameter("mgemail");
		String mgtel = request.getParameter("mgtel");
		
		byte[] mgpassword = mgpasswordStr.getBytes();

		Manager m = new Manager();
		ManagerService managerService = new ManagerService();
		m.setMgaccount(mgaccount);
		m.setMgpassword(mgpassword);
		m.setMgname(mgname);
		m.setMgidentity(mgidentity);
		m.setMgemail(mgemail);
		m.setMgtel(mgtel);
		
		managerService.insertManager(m);
		
		RequestDispatcher rd = request
				.getRequestDispatcher("/index.jsp");
		rd.forward(request, response);
		return;
		
		
	}

}
